import ossaudiodev
import wave
import sys

import audioop



	

f0 = ossaudiodev.open("/dev/audio", "rw")
f0.setparameters(ossaudiodev.AFMT_S16_LE, 2, 44100)

f1 = ossaudiodev.open("/dev/audio1", "rw")
f1.setparameters(ossaudiodev.AFMT_S16_LE, 2, 44100)

f2 = ossaudiodev.open("/dev/audio2", "rw")
f2.setparameters(ossaudiodev.AFMT_S16_LE, 2, 44100)

f3 = ossaudiodev.open("/dev/audio3", "rw")
f3.setparameters(ossaudiodev.AFMT_S16_LE, 2, 44100)

f4 = ossaudiodev.open("/dev/audio4", "rw")
f4.setparameters( ossaudiodev.AFMT_S16_LE, 2, 44100)






matrix = []

list0 = [1.0, 1.0, 1.0, 1.0, 1.0]
list1 = [1.0, 1.0, 1.0, 1.0, 1.0]
list2 = [1.0, 1.0, 1.0, 1.0, 1.0]
list3 = [1.0, 1.0, 1.0, 1.0, 1.0]
list4 = [1.0, 1.0, 1.0, 1.0, 1.0]

matrix.append(list0);
matrix.append(list1);
matrix.append(list2);
matrix.append(list3);
matrix.append(list4);

output = []
output.append(f0)
output.append(f1)
output.append(f2)
output.append(f3)
output.append(f4)
# play stream
while True:
	data = []
  	data.append(f0.read(1000))
  	data.append(f1.read(1000))
  	data.append(f2.read(1000))
  	data.append(f3.read(1000))
  	data.append(f4.read(1000))
  
	for i in range(0, 5):
		out = audioop.mul(data[0], 4, 0.0)
		for j in range(0, 5):
			tmp = audioop.mul(data[j], 4, matrix[i][j])
			out = audioop.add(out, tmp, 4)
		output[i].write(out)
  
  
  #f4.write(out)
  #f0.write(out)
  #f1.write(out)
  #f2.write(out)
  #f3.write(out)
  #for i in range(0,5):
    #out = audioop.mul(data[0], 4, 0.0)
    #
    #for j in range(0, 5):
   #   tmp = audioop.mul(data[j], 4, 1.0)
  #    out = audioop.add(out, tmp, 4)
  #output[i].write(out)
  #out = audioop.mul(data[0], 4, 0.0)
  
  
  
  #data1 = audioop.mul(data1, 4, 3.0)
  #data = audioop.add(data0, data1, 4)tmp
  #f4.write(data);
  #f0.write(data);
#data = f1.read(100)
#f.write(data)    
#data = wf.readframes(chunk)






f.close()
